import sys
sys.path.extend(["F:/ML/BNC", "D:/BNC", "/www/wwwroot/BNC"])

from StockRelation import SpiltTag
from StockRelation.ReWriteTagUpCalendar import cursor, connection

cursor = cursor
connection = connection
STOCK_TAG_TB = 'stocktagrelation'

if __name__ == '__main__':
    # 查看一个标签和他相关的标签的交集大小
    select_relat_tag = "select distinct(tag) from {} where code in (select distinct(code) from {} where tag = %s)".format(STOCK_TAG_TB, STOCK_TAG_TB)
    main_tag = '长三角一体化'

    cursor.execute(select_relat_tag, [main_tag])
    for one_tag_res in cursor.fetchall():
        select_one_tag_codes_set_sql = 'select distinct code,name from {} where tag = %s'.format(STOCK_TAG_TB)
        cursor.execute(select_one_tag_codes_set_sql, [main_tag])

        main_tag_relate_codes_set = set()
        for tag_relate_code_res in cursor.fetchall():
            main_tag_relate_codes_set.add(tag_relate_code_res)

        cursor.execute(select_one_tag_codes_set_sql, [one_tag_res[0]])

        litter_tag_relate_codes_set = set()
        for tag_relate_code_res in cursor.fetchall():
            litter_tag_relate_codes_set.add(tag_relate_code_res)


        if len(litter_tag_relate_codes_set & main_tag_relate_codes_set)  > SpiltTag.TAG_COMBINE_FRQ_LINE:
            print("litter tag:{} \n main_tag :{} \n combine num more than spilt_line".format(one_tag_res[0], main_tag))



